import {
  colorList
} from '../config';

function buildDayTable(tableData) {

  if(tableData == undefined || tableData.length == 0) return [];
  
 // console.log(tableData)
  let tarr = tableData;
 // console.log(tarr)
  // map 映射处理
  tarr = tarr.map(item => {
    item.teacher = item.jsxm;
    item.courseLocation = item.jsmc;
    item.courseName = item.kcmc || item.sname;
    let currentDay = item.kcsj.substring(0,1)
   // console.log(currentDay)
    let startTime = item.kcsj.substring(1,3);
   // console.log(startTime)
    let endTime = item.kcsj.substring(3,5);
   // console.log(endTime)
    item.startTime = item.nums || parseInt(startTime);
    item.endTime = item.enum || parseInt(endTime);
    item.currentDay = item.days || parseInt(currentDay);
    //赋值随机颜色
   // item.color = colorList[Math.round(Math.random() * colorList.length)%colorList.length]
    return item;
  })
  return tarr;
}

function sortDayTable(tarr) {
  return tarr.sort(function (a, b) {
    return a.startTime <= b.startTime;
  })
}
module.exports = {
  buildDayTable,
  sortDayTable
}